package com.example.demo.service.impl;

import com.example.demo.entity.user.UserInfo;
import com.example.demo.mapper.LogMapper;
import com.example.demo.service.LogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.example.demo.entity.user.InsertUser;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import java.util.List;

@Service
public class LogServiceImpl implements LogService {

    @Autowired
    private LogMapper logMapper;

    @Override
    public List<UserInfo> login(InsertUser user) {

        return logMapper.login(user.getName(), user.getPassword());

    }

    @Override
    public SecretKey getAesKey() {
        SecretKey key = null;
        try {
            key = createAes();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return key;

    };

    // 创建加密钥匙
    private SecretKey createAes() throws Exception {
        KeyGenerator keyGen = KeyGenerator.getInstance("AES");
        keyGen.init(256);
        return keyGen.generateKey();
    }

}
